using MicroMsg.Resource.@string;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace MicroMsg.UI.UserContrl
{
	public class MassSendTxtItem : BaseMassSendElement
	{
		private const string TAG = "MassSendTxtItem";
		private const int MAX_ELEMENT_NUM = 400;
		private List<string> strList;
		private Paragraph sParagraph;
		private HyperlinkButton showAllBtn;
		private string lastContentCache;
		private string mStrContent;
		private bool _contentLoaded;
		public MassSendTxtItem()
		{
			this.InitializeComponent();
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.sParagraph = (base.GetTemplateChild("sParagraph") as Paragraph);
			this.showAllBtn = (base.GetTemplateChild("showAllBtn") as HyperlinkButton);
			this.RefreshContent();
		}
		private void RefreshContent()
		{
			if (this.sParagraph == null)
			{
				return;
			}
			if (string.IsNullOrEmpty(this.mStrContent))
			{
				return;
			}
			if (this.mStrContent == this.lastContentCache)
			{
				return;
			}
			this.lastContentCache = this.mStrContent;
			this.sParagraph.get_Inlines().Clear();
			LongTxtCutter longTxtCutter = new LongTxtCutter(this.mStrContent);
			longTxtCutter.ProcessText();
			if (longTxtCutter.textList.get_Count() > 1)
			{
				this.strList = longTxtCutter.textList;
			}
			List<InLineResult> inLineResult = InlineElementHelper.GetInLineResult(longTxtCutter.textList.get_Item(0));
			int num = 0;
			using (List<InLineResult>.Enumerator enumerator = inLineResult.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					InLineResult current = enumerator.get_Current();
					if (current.mInline != null)
					{
						num++;
						this.sParagraph.get_Inlines().Add(current.mInline);
						if (num >= 400)
						{
							Run run = new Run();
							run.set_Text("......");
							this.sParagraph.get_Inlines().Add(run);
							break;
						}
					}
				}
			}
			if (longTxtCutter.textList.get_Count() > 1 && this.showAllBtn != null)
			{
				this.showAllBtn.set_Visibility(0);
				this.showAllBtn.set_Content(strings.Chat_LongTxt_SeeAll);
				this.showAllBtn.add_Click(new RoutedEventHandler(this.moreContentBtn_Click));
				this.showAllBtn.set_Foreground(R.theme.COMMON_BRUSH);
				return;
			}
			this.showAllBtn.set_Visibility(1);
		}
		private void moreContentBtn_Click(object sender, RoutedEventArgs e)
		{
			ToolFunction.GotoPageForUserControl("/Source/UI/Chat/TooLongTxt/LongTxtShowPage.xaml", new object[]
			{
				this.strList,
				true
			}, false);
		}
		public override void SetMsgContent(string msgContent)
		{
			this.mStrContent = msgContent;
			this.RefreshContent();
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/MassSend/UI/MassSendTxtItem.xaml", 2));
		}
	}
}
